<template>
  <div class="custom-navbar-header">
    <view class="custom-navbar">
      <view
        class="nav-left"
        @click="handleBack"
      >
        <uni-icons
          v-if="showBackButton"
          type="arrowleft"
          size="24"
        />
      </view>
      <view class="nav-title">{{ title }}</view>
    </view>
  </div>
</template>

<script lang="ts" setup>
import { onShow } from '@dcloudio/uni-app'

defineProps({
  title: {
    type: String,
    default: '标题'
  },
  showBackButton: {
    type: Boolean,
    default: true
  }
})

onShow(() => {
  //  const pages = getCurrentPages();
  //   showBackButton = pages.length > 1;
})

const handleBack = () => {
  // if (showBackButton) {
  uni.navigateBack()
  // } else {
  // 	// 默认跳转到首页（兜底逻辑）
  // 	uni.switchTab({ url: '/pages/index/index' });
  // }
}
</script>

<style lang="scss" scoped>
.custom-navbar {
	padding-top: var(--status-bar-height); /* 适配状态栏高度 */
	height: calc(44px + var(--status-bar-height));
	display: flex;
	align-items: center;
	background: #ffffff;
	box-shadow: 0 1px 6px #eee;
}
.nav-left {
	width: 60px;
	padding-left: 12px;
}
</style>
